<?
$sub_menu = "230440";
include_once("./_common.php");

check_demo();

auth_check($auth[$sub_menu], "w");

check_token();

if ($w == "")
{
   if (!trim($ms_id))
        alert("멤버쉽을 선택해주세요.");

   if (!trim($bo_table))
        alert("게시판을 선택해주세요.");

    $sql = "select * from $mw_cash[membership_board_table] where ms_id = '$ms_id' and bo_table = '$bo_table'";
    $row = sql_fetch($sql);
    if ($row)
        alert("이미 권한설정되어 있는 게시판입니다.");

    $sql = "insert into $mw_cash[membership_board_table] set ms_id = '$ms_id', bo_table = '$bo_table',
            mp_list = '$mp_list', mp_view = '$mp_view', mp_down = '$mp_down', mp_write = '$mp_write', mp_comment = '$mp_comment' ";
    sql_query($sql);

    $mp_id = mysql_insert_id();
}
else if ($w == "u")
{
   if (!trim($ms_id))
        alert("멤버쉽을 선택해주세요.");

   if (!trim($bo_table))
        alert("게시판을 선택해주세요.");

    $sql = "select * from $mw_cash[membership_board_table] where mp_id = '$mp_id'";
    $row = sql_fetch($sql);
    if ($row[ms_id] != $ms_id || $row[bo_table] != $bo_table) {
        $sql = "select * from $mw_cash[membership_board_table] where ms_id = '$ms_id' and bo_table = '$bo_table'";
        $row = sql_fetch($sql);
        if ($row)
            alert("이미 권한설정되어 있는 게시판입니다.");
    }

    $sql = "update $mw_cash[membership_board_table] set ms_id = '$ms_id', bo_table = '$bo_table',
            mp_list = '$mp_list', mp_view = '$mp_view', mp_down = '$mp_down', mp_write = '$mp_write', mp_comment = '$mp_comment' where mp_id = '$mp_id' ";
    sql_query($sql);
}
else if ($w == "d")
{
    if (!trim($mp_id))
        alert("mp_id 가 없습니다.");

    $sql = "delete from $mw_cash[membership_board_table] where mp_id = '$mp_id'";
    sql_query($sql);
}

goto_url("mw.membership.board.php");
?>
